/*
 * @Author: fuhongliang-TSJ hongliang.fu@4d-bios.com
 * @Date: 2025-09-16 09:32:54
 * @LastEditTime: 2025-09-16 10:53:09
 * @LastEditors: fuhongliang-TSJ hongliang.fu@4d-bios.com
 * @Description: 
 * @FilePath: \lc_-esp32_-s3\components\bsp\bsp_spiffs\bsp_spiffs.c
 * 立创实战派ESP32-S3开发板
 * Copyright (c) 2025 by 4D Bios, All Rights Reserved. 
 */
#include "bsp_spiffs.h"

static const char *TAG = "spiffs";

esp_vfs_spiffs_conf_t conf = {
    .base_path = SPIFFS_BASE,
    .partition_label = "mp3",
    .max_files = 5,
    .format_if_mount_failed = false,
};

esp_err_t bsp_spiffs_mount(void)
{
    esp_err_t ret_val = esp_vfs_spiffs_register(&conf);

    ESP_ERROR_CHECK(ret_val);

    size_t total = 0, used = 0;
    ret_val = esp_spiffs_info(conf.partition_label, &total, &used);
    if (ret_val != ESP_OK) {
        ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret_val));
    } else {
        ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
    }

    return ret_val;
}

esp_err_t bsp_spiffs_unmount(void)
{
    esp_err_t ret_val = esp_vfs_spiffs_unregister(conf.partition_label);

    ESP_ERROR_CHECK(ret_val);

    size_t total = 0, used = 0;
    if (ret_val != ESP_OK) {
        ESP_LOGE(TAG, "Failed to unmount SPIFFS (%s)", esp_err_to_name(ret_val));
    } else {
        ESP_LOGI(TAG, "sucessed to unmount SPIFFS");
    }

    return ret_val;
}